using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using SILAS.Entidades;

namespace SILAS.DAO.Mapping
{
    public class SAPMap : EntityTypeConfiguration<SAP>
    {
        public SAPMap()
        {
            // Primary Key
            this.HasKey(t => t.IdSAP);

            // Properties
            this.Property(t => t.Nombre)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("SAP");
            this.Property(t => t.IdSAP).HasColumnName("IdSAP");
            this.Property(t => t.Nombre).HasColumnName("Nombre");
            this.Property(t => t.FecConstruccion).HasColumnName("FecConstruccion");
            this.Property(t => t.NroPilPublicas).HasColumnName("NroPilPublicas");
            this.Property(t => t.NroFamBenef).HasColumnName("NroFamBenef");
            this.Property(t => t.MontoInversion).HasColumnName("MontoInversion");
            this.Property(t => t.SeClora).HasColumnName("SeClora");
            this.Property(t => t.IdInstSupervisora).HasColumnName("IdInstSupervisora");
            this.Property(t => t.IdTipoSAP).HasColumnName("IdTipoSAP");
            this.Property(t => t.IdInstEjecutora).HasColumnName("IdInstEjecutora");

            // Relationships
            this.HasMany(t => t.Sectors)
                .WithMany(t => t.SAPs)
                .Map(m =>
                    {
                        m.ToTable("SectorSAP");
                        m.MapLeftKey("IdSAP");
                        m.MapRightKey("IdSector");
                    });

            this.HasOptional(t => t.InstEjecutora)
                .WithMany(t => t.SAPs)
                .HasForeignKey(d => d.IdInstEjecutora);
            this.HasOptional(t => t.InstSupervisora)
                .WithMany(t => t.SAPs)
                .HasForeignKey(d => d.IdInstSupervisora);
            this.HasOptional(t => t.TipoSAP)
                .WithMany(t => t.SAPs)
                .HasForeignKey(d => d.IdTipoSAP);

        }
    }
}
